//
//  LKForgetSecrectViewController.m
//  Mideleague_Agent
//
//  Created by Zhiwang on 2020/6/18.
//  Copyright © 2020 Zhiwang. All rights reserved.
//

#import "LKForgetSecrectViewController.h"
#import "VerificationCodeBtn.h"
@interface LKForgetSecrectViewController ()
@property (weak, nonatomic) IBOutlet VerificationCodeBtn *codeBtn;
@property (weak, nonatomic) IBOutlet UITextField *phoneTf;
@property (weak, nonatomic) IBOutlet UITextField *secrectTf;
@property (weak, nonatomic) IBOutlet UITextField *codeTf;

@property (weak, nonatomic) IBOutlet UIButton *loginBtn;

@end

@implementation LKForgetSecrectViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"忘记密码";
    self.codeBtn.layer.cornerRadius = 15;
    self.codeBtn.layer.masksToBounds = YES;
    self.loginBtn.layer.cornerRadius = 25;
    self.loginBtn.layer.masksToBounds = YES;
    self.phoneTf.keyboardType = UIKeyboardTypeNumberPad;
    self.codeTf.keyboardType = UIKeyboardTypeNumberPad;
    [self.phoneTf addTarget:self action:@selector(tfValueChange:) forControlEvents:UIControlEventEditingChanged];
    [self.secrectTf addTarget:self action:@selector(tfValueChange:) forControlEvents:UIControlEventEditingChanged];
    [self.codeTf addTarget:self action:@selector(tfValueChange:) forControlEvents:UIControlEventEditingChanged];
    // Do any additional setup after loading the view from its nib.
}
-(void)tfValueChange:(UITextField *)textField{
    if (self.phoneTf.text.length != 0 && self.secrectTf.text.length != 0  && self.codeTf.text.length != 0) {
        self.loginBtn.backgroundColor = ColorRGB(180, 71, 42);
    }else{
        self.loginBtn.backgroundColor = ColorRGB(137, 105, 93);
    }
}
- (IBAction)getCode:(id)sender {
    if (![NSString checkTelNumber:self.phoneTf.text]) {
        [SVProgressHUD showInfoWithStatus:@"请输入正确的手机号"];
        return;
    }
    [self.codeBtn startTimer];
    NSDictionary *param = @{@"phone":self.phoneTf.text,@"type":@"2"};
    [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:getSmsUrl header:@"" parameters:param progress:^(NSProgress * _Nullable progress) {
        
    } success:^(BOOL isSuccess, id  _Nullable responseObject) {
        [SVProgressHUD showInfoWithStatus:@"验证码发送成功"];
    } failure:^(NSString * _Nullable errorMessage) {
        
    }];
}
- (IBAction)submit:(id)sender {
    if ([NSString isBlankString:self.phoneTf.text]) {
        [SVProgressHUD showInfoWithStatus:@"请输入手机号"];
        return;
    }
    if ([NSString isBlankString:self.secrectTf.text]) {
        [SVProgressHUD showInfoWithStatus:@"请输入6-20位密码"];
        return;
    }
    if ([NSString isBlankString:self.codeTf.text]) {
        [SVProgressHUD showInfoWithStatus:@"请输入验证号"];
        return;
    }
    NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys:self.phoneTf.text,@"phone",self.secrectTf.text,@"pwd",self.codeTf.text,@"sms",@"2",@"role_type", nil];
    [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:forgetSecrectUrl header:@"" parameters:param progress:^(NSProgress * _Nullable progress) {
        
    } success:^(BOOL isSuccess, id  _Nullable responseObject) {
        [SVProgressHUD showInfoWithStatus:@"验证码发送成功"];
        if ([responseObject[@"code"] isEqualToString:@"success"]) {
            [SVProgressHUD showInfoWithStatus:responseObject[@"msg"]];
            [self dismissViewControllerAnimated:YES completion:nil];
        }else{
            [SVProgressHUD showInfoWithStatus:responseObject[@"msg"]];
        }

    } failure:^(NSString * _Nullable errorMessage) {
        
    }];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
